import Cookies from 'js-cookie'
import { ACCESS_TOKEN, USER_ROUTES, USER_INFO } from './vars'

export function getToken() {
  return Cookies.get(ACCESS_TOKEN)
}

export function setToken(token) {
  return Cookies.set(ACCESS_TOKEN, token)
}

export function removeToken() {
  return Cookies.remove(ACCESS_TOKEN)
}

export function getRoutes() {
  const res = sessionStorage.getItem(USER_ROUTES)
  return res ? JSON.parse(res) : null
}

export function setRoutes(list) {
  return sessionStorage.setItem(USER_ROUTES, JSON.stringify(list || []))
}

export function getUserInfo() {
  const res = sessionStorage.getItem(USER_INFO)
  return res ? JSON.parse(res) : null
}

export function setUserInfo(data) {
  console.log({ data })
  return sessionStorage.setItem(USER_INFO, JSON.stringify(data || {}))
}
